package com.woniuxy.Cookie;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @auther linke
 * @create 2021-10-21 14:28
 */
@WebServlet("/cookieDemo05")
public class CookieDemo05 extends HttpServlet {
    /**
     * cookie的生命周期
     * 测试获取cookie
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("cookieDemo05...执行了");

        Cookie[] cookies = req.getCookies();
        //获取cookie
        for (Cookie cookie : cookies) {
            System.out.println(cookie.getName()+"..."+cookie.getValue());//name...tom
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
